using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Text;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Collections.Specialized;
using System.Windows.Markup;
using Sinacor.Infra.UI.Common;
using System.Reflection;
using System.Text.RegularExpressions;
using System.IO;

namespace Sinacor.Infra.UI.Controls.SmartClient.Validation
{
    public class FolderPickerValidationRule : BaseValidationRule
    {
        public FolderPickerValidationRule() : base() {}
        public FolderPickerValidationRule(DependencyObject source) : base(source) {}
        public FolderPickerValidationRule(DependencyObject source, DependencyProperty property) : base(source, property) {}
        public FolderPickerValidationRule(DependencyObject source, DependencyProperty property, object errorContent) : base(source, property, errorContent) {}
		public FolderPickerValidationRule(object errorContent) : base(errorContent) { }

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            ValidationResult result = ValidationResult.ValidResult;
            if (this.IsEnabled)
            {
                if (value != null)
                {
                    string filePath = (string)value;
                    if (!ValidateFilePicker(filePath))
                        result = new ValidationResult(false, this.ErrorContent);
                }
            }
            return result;
        }

        private bool ValidateFilePicker(string path)
        {
            if (String.IsNullOrEmpty(path))
                return true;

			return Directory.Exists(path);
        }
    }
}